home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / cpu_c.zip / CPUINFO.C < prev   
C/C++ Source or Header  |  1991-10-02  |  4KB  |  94 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <dos.h>
  4.  
  5. #define         _8088           0
  6. #define         _NECV20         1
  7. #define         _80188          2
  8. #define         _80286          3
  9. #define         _80386          4
  10.  
  11.  
  12. char *CPUStrings[] =
  13.                 {
  14.                    "8088/8086",
  15.                    "NEC V20/V30",
  16.                    "80188/80186",
  17.                    "80286",
  18.                    "80386"
  19.                 };
  20.  
  21.  
  22. int CPUInfo( void )
  23. {
  24.     /* ---------------------------------------------------------------- */
  25.     /* The following Code distinguishes between 286+ (and above) and    */
  26.     /* the other chips since 286+ (and above) pushes SP prior to        */
  27.     /* decrementing its value for a PUSH SP instruction...  The earlier */
  28.     /* processors will decrement SP first...                            */
  29.     /* ---------------------------------------------------------------- */
  30.     __emit__(0x8B,0xDC);                        /* MOV    BX, SP        */
  31.     __emit__(0x54);                             /* PUSH   SP            */
  32.     __emit__(0x58);                             /* POP    AX            */
  33.     __emit__(0x87,0xE3);                        /* XCHG   BX, SP        */
  34.     if ( _AX == _BX )
  35.     {
  36.     /* ---------------------------------------------------------------- */
  37.     /* The following Code distinguishes between a 286 and higher        */
  38.     /* processors since the 286 sets bits 12-14 of the FLAGS to zero    */
  39.     /* after a PUSHF...                                                 */
  40.     /* ---------------------------------------------------------------- */
  41.         __emit__(0xB8,0x00,0x70);               /* MOV    AX, 7000h     */
  42.         __emit__(0x50);                         /* PUSH   AX            */
  43.         __emit__(0x9D);                         /* POPF                 */
  44.         __emit__(0x9C);                         /* PUSHF                */
  45.         __emit__(0x58);                         /* POP    AX            */
  46.  
  47.         if ( ( _AX & 0x7000 )==0x0000 )
  48.             return( _80286 );
  49.         else
  50.             return( _80386 );
  51.     }
  52.  
  53.     /* ---------------------------------------------------------------- */
  54.     /* The Following Code singles out the 80186 and 80188 since the Top */
  55.     /* three bits in CL are excluded by a shift instruction on those    */
  56.     /* processors... i.e. Only the lower 5 bits of CL is used.. Using   */
  57.     /* the value of 33 in CL is guaranteed to clear the register with   */
  58.     /* the lower processors..                                           */
  59.     /* ---------------------------------------------------------------- */
  60.     __emit__(0xB0, 0xFF);                       /* MOV    AL, 0FFh      */
  61.     __emit__(0xB1, 0x21);                       /* MOV    CL, 21h       */
  62.     __emit__(0xD2, 0xE8);                       /* SHR    AL, CL        */
  63.  
  64.     if ( _AL != 0x00 )
  65.         return( _80188 );
  66.  
  67.     /* ---------------------------------------------------------------- */
  68.     /* The NEC V20/V30 carry forth a string instruction with REP and    */
  69.     /* segment override even when Interrupts are enabled (unlike the    */
  70.     /* 8088/8086)...                                                    */
  71.     /* ---------------------------------------------------------------- */
  72.     enable();                                   /* Ensure int's enabled */
  73.     __emit__(0x56);                             /* PUSH   SI            */
  74.     __emit__(0xB9,0xFF,0xFF);                   /* MOV    CX, 0FFFFh    */
  75.     __emit__(0xF3,0x26,0xAC);                   /* REP LODS BPTR ES:[SI]*/
  76.     __emit__(0x5E);                             /* POP    SI            */
  77.     if ( _CX == 0x00 )
  78.         return( _NECV20 );
  79.     return(  _8088 );
  80. }
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87. int main(void)
  88. {
  89.     printf("CPU Detection Routine\n");
  90.     printf("--- --------- -------\n\n");
  91.     printf("Current Processor is: %s\n\n", CPUStrings[ CPUInfo() ]);
  92.     return( 0 );
  93. }
  94.